import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import store from '@/store'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/musiclistitem',
    name: 'MusicListItem',
    component: () => import('@/views/MusicList.vue')
  },
  {
    path: '/search',
    name: 'Search',
    component: () => import('@/views/Search.vue')
  },
  {
    path: '/login',
    name: 'Logon',
    component: () => import('@/views/Login.vue')
  },
  {
    path: '/userinfo',
    name: 'UserInfo',
    beforeEnter: (to, from, next) => {
      if (store.state.isLogin) {
        next()
      } else {
        next('/login')
      }
    },
    component: () => import('@/views/UserInfo.vue')
  },
  {
    path: '/mv',
    name: 'Mv',
    component: () => import('@/views/MV.vue')
  },
  {
    path: '/moment',
    name: 'Moment',
    component: () => import('@/views/Moment.vue')
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

router.beforeEach((to, from) => {
  if (to.path == '/login' || to.path == '/moment') {
    store.state.isFooterPlayerShow = false
  } else {
    store.state.isFooterPlayerShow = true
  }

})

export default router
